/* Project ir_T01
Infrared controller PIC12F675
*/

#include <pic.h>

__CONFIG(
INTIO
& UNPROTECT
& BORDIS
& MCLRDIS
& WDTDIS
& PWRTEN
);

__IDLOC(F675);

#define SW GPIO0
#define IR GPIO4
#define LED GPIO5

#define RH 100
#define RL 50
#define DH 18
#define DL1 53
#define DL0 18
#define N 8
#define ch1 255
#define ch2 58

const unsigned char sig[N] = {
0,0,1,0,1,0,0,0
};

void shot(unsigned char s){
IR = s;
NOP(); NOP(); NOP();
NOP(); NOP(); NOP();
NOP(); NOP(); NOP();
IR = 1;
}

void main(void){

unsigned char i, tl;

CMCON = 0b00000111;
ANSEL = 0b00000000;
GPIO = 0;
TRISIO = 0b00000001;
WPU = 0b00000001;
GPPU = 0;
OPTION = 0b00000100;

LED = 1;
IR = 1;


while(1){
while(SW);

LED = 0;

TMR0 = 0;
while(TMR0 < ch1);
while(TMR0 < ch2);

LED = 1;

//Reader H
TMR0 = 0;
while(TMR0 < RH) shot(0);

//Reader L
TMR0 = 0;
while(TMR0 < RL) shot(1);

for(i = 0; i < N; i++){

//Signal H
TMR0 = 0;
while(TMR0 < DH) shot(0);

//Signal L
TMR0 = 0;
if(sig[i])
tl = DL1;
else
tl = DL0;
while(TMR0 < tl) shot(1);
}

//Stop bit
TMR0 = 0;
while(TMR0 < DH) shot(0);
}
}


               戻る